home *** CD-ROM | disk | FTP | other *** search
- /*================================================================================
- modalScrollText.c
-
- circa 1991 by Greg Anderson
- greggor@apple.com
-
- FREE DISTRIBUTION--use and enjoy
-
- This file contains routines that display a modal dialog box
- containing a scrolling item list
- ================================================================================*/
- #include "ModalScrollText.h"
-
- #include "DialogUtilities.h"
- #include "TEUtilities.h"
- #include "FailureHandler.h"
-
- /*----------------------------------------------------------------------
- ScrollingTextFilter
-
- This ModalDialogProc has two functions:
-
- 1. It handles clicks in the SplashScreen's scrollbar
- 2. It eats keydown events so that the user cannot edit
- the text of the About Box.
- ----------------------------------------------------------------------*/
- pascal Boolean ScrollingTextFilter( DialogPtr dlog, EventRecord* event, short* itemHit )
- {
- ControlHandle scrollbar;
- TEHandle te;
- Point localClick;
- short itemType;
- short theItem;
- Handle itemHandle;
- Rect box;
-
- SetPort(dlog);
-
- GetDItem( dlog, kScrollbarItem, &itemType, (Handle*)&scrollbar, &box );
- te = (TEHandle)GetCRefCon( scrollbar );
- /*
- // Handle clicks in the scrollbar
- */
- localClick = event->where;
- GlobalToLocal( &localClick );
- if( event->what == mouseDown )
- {
- theItem = FindDItem(dlog,localClick) + 1;
- if( theItem == kScrollbarItem )
- {
- ScrollBarClick( scrollbar, localClick );
- *itemHit = theItem;
- return true;
- }
- if( theItem == kEditTextItem )
- {
- Point mousePt;
-
- GetMouse( &mousePt );
- TEClick( mousePt, false, te );
- FixScrollBar( scrollbar );
-
- return true;
- }
- }
- /*
- // Check to see if the RETURN key was pressed
- */
- if( event->what == keyDown )
- {
- char key = (char)(event->message & charCodeMask);
-
- if( key == '\r' )
- {
- *itemHit = 1;
- return true;
- }
- /*
- // We want to eat any keyDown event that is not a Return,
- // a cut or a copy
- */
- else if( (event->modifiers & cmdKey) && ((key == 'c') || (key == 'x')) )
- {
- /*
- // Translate 'cut' into 'copy'
- */
- event->message = (event->message & ~ charCodeMask) | 'c';
- }
- /*
- // Transmogrify the keyDown event into a null event
- // because we want to ignore it
- */
- else
- {
- event->what = nullEvent;
- }
- }
-
- return CutPasteFilter( dlog, event, itemHit );
- }
-
- /*----------------------------------------------------------------------
- ModalScrollText
- ----------------------------------------------------------------------*/
- void ModalScrollText( Str255 title, Ptr textToShow, Size lengthOfText )
- {
- DialogPtr dlog;
- TEHandle te;
- ControlHandle scrollbar;
- Handle itemHandle;
- short itemType;
- Rect box;
- short itemHit;
-
- dlog = nil;
-
- TRY
- {
- /*
- // Set up Dialog box
- */
- dlog = GetNewDialog( kModalScrollID, (Ptr)0L, (WindowPtr)-1L);
- FailResErrorOrNil( dlog );
- SetPort(dlog);
- ParamText( title, nil, nil, nil );
- InstallDefaultOutline(dlog,1);
- CenterAndShowDialog(dlog);
- /*
- // Set the text of the currently open textedit item
- // (the first one will be selected...)
- */
- GetDItem( dlog, kEditTextItem, &itemType, &itemHandle, &box );
- te = ((DialogRecord*)dlog)->textH;
- TESetText( textToShow, lengthOfText, te );
- /*
- // Get a reference to the scrollbar & set its refCon
- // to the textEdit item it controls
- */
- GetDItem( dlog, kScrollbarItem, &itemType, (Handle*)&scrollbar, &box );
- SetCRefCon( scrollbar, (long)te );
- /*
- // Select and draw the window
- */
- SelectWindow(dlog);
- SetPort(dlog);
- DrawDialog(dlog);
- /*
- // Wait for user to click "Okay"
- */
- do
- {
- ModalDialog( (ProcPtr)ScrollingTextFilter, &itemHit );
- /*
- // This is necessary to fix up the scrollbar
- // after an autoscroll.
- */
- //if( itemHit == kEditTextItem )
- // FixScrollBar( scrollbar );
- } while( itemHit != 1 );
- DisposDialog(dlog);
- }
- EXCEPT
- {
- if( dlog != nil )
- DisposDialog(dlog);
- DebugStr( "\pCould not bring up dialog box" );
- }
- ENDTRY
- }
-